package com.cn.hotel.servlet.back.company;

import com.alibaba.fastjson.JSONObject;
import com.cn.hotel.model.CompanyModel;
import com.cn.hotel.service.ICompanyService;
import com.cn.hotel.service.impl.CompanyServiceImpl;
import com.cn.hotel.util.Upload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/company/companyAdd")
public class CompanyAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        Upload.imgUpload(req);
        CompanyModel companyModel = new CompanyModel();
        companyModel.setCompanyName((String) req.getAttribute("companyName"));
        companyModel.setLogo((String) req.getAttribute("logo"));
        companyModel.setAd((String) req.getAttribute("ad"));
        companyModel.setNet((String) req.getAttribute("net"));
        companyModel.setIntroduce((String) req.getAttribute("introduce"));
        companyModel.setVersion((String) req.getAttribute("version"));
        ICompanyService iCompanyService = new CompanyServiceImpl();
        int result = iCompanyService.add(companyModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",result);
        resp.getWriter().println(jsonObject);
    }
}
